const { tool,api } = getApp();
Page({

    data: {
        info: {},   // 用户信息
        role:2,
        funs: [], //表单hashMap
        routes:[], //路由hashMap
        funs2:[
          {
              title: '学生',
              list: [
                  { id: 1,title: '我的信息', icon: '/assets/icon/fun_0.png' },
                  { id: 2,title: '我的课题', icon: '/assets/icon/fun_1.png' },
              ]
          },
          {
              title: '周报',
              list: [
                  { id: 3,title: '我的周报', icon: '/assets/icon/fun_3.png' },
                  { id: 4,title: '写周报', icon: '/assets/icon/fun_4.png' },
              ]
          },
          {
              title: '系统',
              list: [
                  { id: 5,title: '文件上传', icon: '/assets/icon/fun_5.png' },
                  { id: 6,title: '退出登录', icon: '/assets/icon/fun_7.png' },
              ]
          }
      ],
      funs1:[
        {
            title: '教师',
            list: [
                { id: 1,title: '我的信息', icon: '/assets/icon/fun_0.png' },
                { id: 2,title: '我的课题', icon: '/assets/icon/fun_1.png' },
                { id: 3,title: '发布课题', icon: '/assets/icon/releaseTopic.png' },
            ]
        },
        {
            title: '我的学生',
            list: [
                { id: 4,title: '学生预约', icon: '/assets/icon/studentOrder.png' },
                { id: 5,title: '学生周报', icon: '/assets/icon/fun_3.png' },
                { id: 6,title: '学生文件', icon: '/assets/icon/studentFile.png' },
            ]
        },
        {
            title: '系统',
            list: [
                { id: 7,title: '文件上传', icon: '/assets/icon/fun_5.png' },
                { id: 8,title: '退出登录', icon: '/assets/icon/fun_7.png' },
            ]
        }
    ],
    funs0:[
      {
          title: '管理员',
          list: [
              { id: 1,title: '我的信息', icon: '/assets/icon/fun_0.png' },
              { id: 2,title: '课题审核', icon: '/assets/img/admin/topic_audit.png' },
              { id: 3,title: '课题分类', icon: '/assets/img/admin/topic_classify.png' },
          ]
      },
      {
          title: '教师管理',
          list: [
              { id: 4,title: '教师列表', icon: '/assets/img/admin/teacher_list.png' },
              { id: 5,title: '注册教师', icon: '/assets/img/admin/teacher_add.png' },
              { id: 6,title: '职位管理', icon: '/assets/img/admin/station.png' },
          ]
      },
      {
        title: '学生管理',
        list: [
            { id: 7,title: '学生列表', icon: '/assets/img/admin/student_list.png' },
            { id: 8,title: '班级', icon: '/assets/img/admin/class_depth.png' },
            { id: 9,title: '系部', icon: '/assets/img/admin/depth.png' },
        ]
    },
      {
          title: '系统',
          list: [
              { id: 10,title: '文件上传', icon: '/assets/icon/fun_5.png' },
              { id: 11,title: '退出登录', icon: '/assets/icon/fun_7.png' },
          ]
      }
  ],
  routes0:['','/pages/user/info/index','/pages/user/admin/topicList/index','/pages/user/admin/topicType/index','/pages/user/admin/teacherList/index','/pages/user/admin/addTeacher/index','/pages/user/admin/station/index','/pages/user/admin/studentList/index','/pages/user/admin/classAndDepth/index','/pages/user/admin/depth/index','/pages/user/agree/index'],
  routes1:['','/pages/user/info/index','/pages/user/teacher/topic/list/index',
  '/pages/user/teacher/releaseTopic/releaseTopic','/pages/user/teacher/studentOrder/list/list','/pages/user/teacher/stuReport/list/list','/pages/user/teacher/stuFile/stuFile','/pages/user/agree/index'],
  routes2:['','/pages/user/info/index','/pages/user/class/index','/pages/user/report/list/index','/pages/user/report/add/index','/pages/user/agree/index'],
    },

    // 使用方法
    click(e) {
        let { id } = e.currentTarget.dataset;
        let { open_id } = this.data.info;
        let role=this.data.role;
        let routes=[];
        switch(role){
          case 0: routes=this.data.routes0; break;
          case 1: routes=this.data.routes1; break;
          case 2: routes=this.data.routes2; break;
          default:this.exit(); break;
        }
        if(id>=routes.length) this.exit();
        else api.navigateTo(routes[id]);
    },
    exit(){
        api.clearStorage();
        api.showModal('提示','退出登录',false).then(res => {
          api.navigateTo('/pages/user/login/index');
        });
    },
    onLoad(){
      console.log("onLoad")
    },
    onReady(){
      console.log("onReady")
      if(this.data.role==2){
        this.setData({
          funs:this.data.funs2
        })
      }else if(this.data.role==1){
        this.setData({
          funs:this.data.funs1
        })
      }else if(this.data.role==0){
        this.setData({
          funs:this.data.funs0
        })
      }
    },
    // 页面加载
    onShow() {
      console.log("onShow")
      tool.getUserInfo().then(res => {
        console.log('res1:',res)
        this.setData({ info:res });
    })
    api.getStorage('role').then(res=>{
      console.log("res2:",res)
      this.setData({role:res})
    })
        
    },
    
})